/*
 * Copyright (C) 2012 Rothens
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package rpg.entities;

import rpg.Maps.Map;
import rpg.entities.eventhandlers.EventHandler;
import rpg.entities.properties.Property;
import rpg.gfx.gui.Bar;
import rpg.gfx.Bitmap;
import rpg.gfx.Screen;

/**
 * rothens.tarhely.biz
 *
 * @author Rothens
 */
public abstract class Sprite extends Entity{

    protected Bar healthBar;
    protected Bar XpBar;
    public Bitmap bitmaps[];
    private EventHandler eh = null;
    private Property prop = null;
    private int xRenderOffset = -10;
    private int yRenderOffset = -10;

    public Sprite() {
    }

    public Bar getHealthBar() {
        return healthBar;
    }

    public Bar getXpBar() {
        return XpBar;
    }
    

    public abstract Bitmap getDrawGraphics();

    public EventHandler getEh() {
        return eh;
    }
    
    public boolean isInView(Screen.Renderable r) {
        int diff = 32;
        if (r.topLeft.getX() - diff < getProp().getLocation().getX() && r.bottomRight.getX() + diff > getProp().getLocation().getX()
                && r.topLeft.getY() - diff < getProp().getLocation().getY() && r.bottomRight.getY() + diff > getProp().getLocation().getY()) {
            setxRenderOffset(getProp().getLocation().getX() - r.topLeft.getX());
            setyRenderOffset(getProp().getLocation().getY() - r.topLeft.getY());
            return true;
        }
        return false;
    }

    public void setEh(final EventHandler eh) {
        this.eh = eh;
    }

    public Property getProp() {
        return prop;
    }

    public void setProp(final Property prop) {
        this.prop = prop;
    }

    public Map getMap() {
        return getProp().getLocation().getMap();
    }

    public void setMap(final Map map) {
        getProp().getLocation().setMap(map);
    }

    public int getxRenderOffset() {
        return xRenderOffset;
    }
    
    public void setxRenderOffset(final int xRenderOffset) {
        this.xRenderOffset = xRenderOffset;
    }
    
    public int getyRenderOffset() {
        return yRenderOffset;
    }
    
    public void setyRenderOffset(final int yRenderOffset) {
        this.yRenderOffset = yRenderOffset;
    }
}
